package com.hy.doubleCompete.Two127;

/**
 * Created With IntelliJ IDEA.
 * Descriptions:
 * User:Mr.Du
 * Date:2024/3/30
 * Time:23:06
 */
public class MinimumSubarrayLength2 {

    public int minimumSubarrayLength(int[] nums, int k) {
        int n = nums.length, res = 2000000, cnt = 0;
        int l = 0, r = 0;
        while(r < n){
            if(nums[r] >= k) return 1;
            cnt |= nums[r];
            while(cnt >= k){
                res = Math.min(res, r - l + 1);
                // 这块不知道如何复原了
                cnt &= ~nums[l++] + (nums[l++] % 2 == 0?0:1);
            }
            r++;
        }
        return res == 2000000?-1:res;
    }

    public static void main(String[] args) {
        MinimumSubarrayLength2 minimumSubarrayLength2 = new MinimumSubarrayLength2();
        int[] nums = {2,32,27,1};
        System.out.println(minimumSubarrayLength2.minimumSubarrayLength(nums, 59));
        int x = 59; // 原始数 x
        int result = x | 2; // 对 x 进行或运算，设置某些位为 1
        int mask = ~2; // 1 的二进制表示取反，得到掩码
        int restoredX = result & mask; // 清除不需要的位，得到复原的数 x


        System.out.println(restoredX);
    }

}
